package org.spolo.android.support.tween;

import org.spolo.android.support.nodetree.Vcanvas;

/**
 * 这是一个递增量的差值器例如:1,2,3...
 * 
 * @date 2012-5-22
 */
public class IntegerInterpolate extends InterpolateBase {
	private float howlong;
	private float dx;

	/**
	 * @param v
	 *            所要操作的Vcanvas对象
	 * @param y
	 *            从0开始最终要达到的数值
	 * @param time
	 *            整个变化持续的时间
	 * @param type
	 *            此插值所要用来做什么变化,值是取自Vcanvas.MOVE...
	 */
	public IntegerInterpolate(Vcanvas v, float y, long time, int type) {
		super(v, type);
		this.dx = y;
		this.howlong = time;
	}

	@Override
	public void stepIt(long tick) {
		float factor = ((tick - startTick) / this.howlong);
		if (factor >= 1.0) {
			Target.setValues(this.changeType, (dx), 0);
			this.isFinish = true;
			return;
		}
		float mx = factor * dx;
		Target.setValues(this.changeType, mx, 0);
		this.isFinish = factor > 1.0;
	}
}
